/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.vladimirkolarevic.eventplanner.tapestry.pages;

import java.util.Date;

import com.vladimirkolarevic.eventplanner.City;
import com.vladimirkolarevic.eventplanner.DateAndTime;
import com.vladimirkolarevic.eventplanner.Event;
import com.vladimirkolarevic.eventplanner.Location;
import com.vladimirkolarevic.eventplanner.User;
import com.vladimirkolarevic.eventplanner.beans.CityBean;
import com.vladimirkolarevic.eventplanner.beans.DateAndTimeBean;
import com.vladimirkolarevic.eventplanner.beans.EventBean;
import com.vladimirkolarevic.eventplanner.beans.LocationBean;
import com.vladimirkolarevic.eventplanner.beans.UserBean;
import com.vladimirkolarevic.eventplanner.service.MembershipsService;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.hibernate.annotations.CommitAfter;
import org.apache.tapestry5.ioc.annotations.Inject;

/**
 * 
 * @author Vlada
 */
public class Register {

	@InjectPage
	private Thanks thanks;

	@Inject
	private MembershipsService membership;

	@Property
	@Persist("flash")
	private User user;

	@SetupRender
	public void createObject() {
		user = new UserBean();
	}

	Object onSuccess() {

		User u = membership.getUserByUserName(user.getUserName());
		if (u == null) {

			Long id = membership.addUser(user);

			return thanks;
		} else
			return this;
	}
}
